package com.yxkj.syh.app.huarong.activities.creat.address;

import android.app.Application;
import android.view.View;

import androidx.annotation.NonNull;
import androidx.databinding.ObservableField;
import androidx.lifecycle.MutableLiveData;

import com.alibaba.android.arouter.launcher.ARouter;
import com.syh.app.basic.base.view_model.BaseViewModel;
import com.syh.app.basic.bindingAdp.view_click.ClickEvent;
import com.syh.app.basic.utils.Tooast;
import com.syh.app.basic.utils.net.ApiObserver;
import com.trello.rxlifecycle2.android.ActivityEvent;
import com.yxkj.syh.app.huarong.bean.UserMainInfo;
import com.yxkj.syh.app.huarong.bean.UserMainInfoResponse;
import com.yxkj.syh.app.huarong.constants.ArouterPath;
import com.yxkj.syh.app.huarong.data_center.DataCache;
import com.yxkj.syh.app.huarong.data_center.model.AccountModel;

import java.util.List;

/**
 * 创建者：SYH
 * 时间：2020/5/21 17:26
 * 编辑者：SYH、
 * 标签：
 * 补充说明：
 */
public class FromAddressesVM extends BaseViewModel<ActivityEvent> {
    private UserMainInfo fromUserMainInfo;

    public FromAddressesVM(@NonNull Application application) {
        super(application);
    }

    public ObservableField<String> ofName = new ObservableField<>();
    public ObservableField<String> ofAddress = new ObservableField<>();
    public ObservableField<Boolean> ofHasAddress = new ObservableField<>(Boolean.FALSE);

    public MutableLiveData<UserMainInfo> mldUserMainInfo = new MutableLiveData<>();

    public ClickEvent editClick = new ClickEvent() {
        @Override
        public void onClick(View view) {
            ARouter.getInstance().build(ArouterPath.EDIT_ADDRESS_ACTIVITY).withSerializable("userMainInfo",mldUserMainInfo.getValue()).navigation();
        }
    };

    public void userMainInfo() {
        AccountModel.getAccountModel().userMainInfo(mLifecycleProvider.bindToLifecycle(), new ApiObserver<UserMainInfoResponse>() {
            @Override
            public void onSuccess(UserMainInfoResponse userMainInfoResponse) {
                fromUserMainInfo = userMainInfoResponse.getData();
                mldUserMainInfo.setValue(fromUserMainInfo);
            }

            @Override
            public void onFailed(int code, String msg) {
                Tooast.warning(msg);
            }
        });
    }

    @Override
    protected void onResume() {
        super.onResume();
        userMainInfo();
    }
}
